{extend name="base:base" /}
{block name="body"}  


<?php 
$rules_arr = explode(',', $rules);
$rules_arr = array_filter($rules_arr);

?>


<form action="<?php echo url('menu_rule_bind') ?>" method="post" class="update_rule">
    <input type="hidden" name="id" value="{$Think.get.id}" />
    <style>
        td.title {background:#f9f9f9; font-weight:bold;}
    </style>
    <div class="table-common">     

        <button type="submit" class="btn btn-primary ajax-post" target-form="update_rule">更新规则</button>
        <span>已绑定<?php echo count($rules_arr); ?>条</span>
    </div>
    <table class="table table-hover">
        <?php
        foreach ($service_annotation as $k => $v) {
            ?>
            <tr>
                <td class='title'></td>
                <td class='title'><?php echo $k; ?></td>
                <td class='title'><?php echo $v['title']; ?></td>
                <td class='title'>Rule</td>
            </tr>
            <?php
            if (isset($v['child'])) {
                foreach ($v['child'] as $k2 => $v2) {
                    $rule = $dir . '/' . $k . '/' . $k2;
                    $rule = hump_to_underline($rule);
                    ?>
                    <tr <?php
                            if (in_array($rule, $rules_arr)) {
                                echo 'class="active"';
                            }
                            ?>>
                        <td><input type="checkbox" name="rules[]" <?php
                            if (in_array($rule, explode(',', $rules))) {
                                echo 'checked';
                            }
                            ?> value="<?php echo $rule; ?>"></td>
                        <td><?php echo $k2; ?></td>
                        <td><?php echo isset($v2['title']) ? $v2['title'] : '<span style="color:red">未设置title标签</span>'; ?></td>
                        <td><?php echo $rule; ?></td>
                    </tr>
            <?php
        }
    }
    ?>
            <?php
        }
        ?>
    </table>
</form>

{/block}

{block name="foot_js"}
<script>
    $(function () {
        $(".table tr").click(function () {
            var hasSelected = $(this).hasClass("active");
            $(this)[hasSelected ? "removeClass" : "addClass"]("active").find(":checkbox").prop("checked", !hasSelected);
        })
    });
</script>
{/block}